var express = require('express');
var router = express.Router();
var path = require('path');
const { use } = require('./users');
var sqlite3 = require('sqlite3').verbose();

/* GET home page. */
router.get('/', function(req, res, next) {
  //http://localhost:3000/kuan?app=cdscdscds&username=zj1
  var username=req.query.username;
  console.log("username:",username)
  var app=req.query.app;
  app=app.toString()
  var kk;
  var db=new sqlite3.Database(path.join(__dirname,"../public/db/data.s3db"));
  kk=__dirname;
  console.log("kk:",kk)
  /*db.run(`create table fancy (user VARCHAR,app VARCHAR)`, function(
    err
  ) {
    if (err) throw err;
    console.log("Create Table Success!");
  });*/
    //sqlStr1="UPDATE `no3` SET answer = r1 WHERE user = 'zj1' and wt = 'r1'"

  /*db.run("UPDATE love SET app = ? WHERE user = ?",app,username);*/
  db.run("insert into love values (?,?)",username,app);



    //var r=db.prepare(`UPDATE no3 SET answer = ? WHERE user = ? and wt = ?`,r1,"zj1","r1");
    //r.exec();
  db.close(function(err){
    if (err) throw err;
  })
  res.render('TJ', { title: '提交成功' });
});

module.exports = router;
